package ca.michaelmaguire.client.midlet;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.midlet.MIDlet;

public class UpdatePingThread extends Thread {

	public void run() {
		try {

			MIDlet midlet = SampleMIDlet.getMIDlet();

			String updatePingUrl = midlet.getAppProperty("x-md-pingurl");

			HttpConnection httpConnection = (HttpConnection) Connector
					.open(updatePingUrl);

			final int responseCode = httpConnection.getResponseCode();

			final Display display = Display.getDisplay(midlet);
			display.callSerially(new Runnable() {
				public void run() {
					Form responseForm = new Form("Response");
					responseForm.append("http response: " + responseCode);
					display.setCurrent(responseForm);

				}
			});

		} catch (Throwable t) {
			// Bummer
		}
	}
}
